<!--
    设备超期统计
 -->
 <template>
    <div class="page">
        <div class="nuclein-query">
            <div>设备超期统计</div>
            <div style="margin-left: auto;">
                <!-- <el-button type="primary" @click="handlerAdd()">添加</el-button> -->
            </div>
        </div>
        <!-- 表格 -->
        <div class="content-row">
            <el-table :data="tableData" style="width: 100%" border>
                <el-table-column label="设备名称" prop="deviceName">
                </el-table-column>
                <el-table-column label="设备编号" prop="deviceSn">
                </el-table-column>
                <el-table-column label="设备投入使用时间" prop="deviceBuyTime">
                </el-table-column>
                <el-table-column label="是否到期" prop="cycleState">
                    <template slot-scope="scope">
                        <el-tag :type="scope.row.cycleState? 'danger' : 'success'">
                            {{scope.row.cycleState?'已到期':'未到期'}}
                        </el-tag>
                    </template>
                </el-table-column>
                <el-table-column label="到期时间" prop="maturityTime">
                </el-table-column>
            </el-table>
        </div>
        <!-- 分页 -->
        <div class="pagination">
            <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="page"
                :page-sizes="[10, 20, 30, 40]" :page-size="size" layout="total, sizes, prev, pager, next, jumper"
                :total="total">
            </el-pagination>
        </div>
    </div>
</template>

<script>
import { overdue } from '../../api/api'
import commonFunction from '../../utils/commonFunction'
import commonData from '../../utils/commonData'
export default {

  data () {
    return {
      dialogFormVisible: false,
      deviceLogType: commonData.deviceLogType,
      total: 10,
      page: 1,
      size: 10,
      formLabelWidth: '160px',
      tableData: []
    }
  },
  created () {
    this.gitList()
  },
  methods: {
    // 获取
    gitList () {
      const data = {
        page: this.page,
        limit: this.size
      }
      overdue({ ...data }).then(res => {
        if (res.code == 0) {
          const { total, records } = res.page
          this.total = total
          this.tableData = records.map(item => {
            const deviceBuyTime = commonFunction.getTimeFormat(+new Date(item.deviceBuyTime), 'YYYY-MM-DD hh:mm:ss')
            const maturityTime = commonFunction.getTimeFormat(+new Date(item.maturityTime), 'YYYY-MM-DD hh:mm:ss')
            return {
              ...item,
              deviceBuyTime,
              maturityTime
            }
          })
        } else {
          this.$message.error(res.msg)
        }
      })
    },
    // 分页
    handleSizeChange (val) {
      this.size = val
      this.gitList()
    },
    handleCurrentChange (val) {
      this.page = val
      this.gitList()
    }
  }
}
</script>

<style scoped>
.page {
    position: relative;
    height: 100%;
}

.nuclein-query {
    display: flex;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid #DCDFE6;
}

.content-row {
    overflow: hidden;
}

.device-type {
    padding: 20px 20px 10px 20px;
}

/* 分页 */
.pagination {
    width: 100%;
    padding: 20px;
    border-top: 1px solid #DCDFE6;
}
</style>
